***preamble

clear
clear matrix
clear mata
set maxvar 30000

***load data

import excel "${path}\data\text\word_count.xlsx", sheet("Sheet1") firstrow clear

***prepare outcomes 

foreach v of varlist evolution_regex motion_regex matter_regex energy_regex reproduction_regex climate_regex pollution_regex earth_regex tectonics_regex universe_regex all_non_evo_regex word_count_raw {
gen ln_`v'= ln(`v'+1)
}

***prepare treatments

foreach v of var * {
	rename `v' `=lower("`v'")'
}
destring year, replace

gen state_code = .

replace state_code = 1 if state == "Alabama"
replace state_code = 2 if state == "Alaska"
replace state_code = 4 if state == "Arizona"
replace state_code = 5 if state == "Arkansas"
replace state_code = 6 if state == "California"
replace state_code = 8 if state == "Colorado"
replace state_code = 9 if state == "Connecticut"
replace state_code = 10 if state == "Delaware"
replace state_code = 11 if state == "District of Columbia"
replace state_code = 12 if state == "Florida"
replace state_code = 13 if state == "Georgia"
replace state_code = 15 if state == "Hawaii"
replace state_code = 16 if state == "Idaho"
replace state_code = 17 if state == "Illinois"
replace state_code = 18 if state == "Indiana"
replace state_code = 19 if state == "Iowa"
replace state_code = 20 if state == "Kansas"
replace state_code = 21 if state == "Kentucky"
replace state_code = 22 if state == "Louisiana"
replace state_code = 23 if state == "Maine"
replace state_code = 24 if state == "Maryland"
replace state_code = 25 if state == "Massachusetts"
replace state_code = 26 if state == "Michigan"
replace state_code = 27 if state == "Minnesota"
replace state_code = 28 if state == "Mississippi"
replace state_code = 29 if state == "Missouri"
replace state_code = 30 if state == "Montana"
replace state_code = 31 if state == "Nebraska"
replace state_code = 32 if state == "Nevada"
replace state_code = 33 if state == "New Hampshire"
replace state_code = 34 if state == "New Jersey"
replace state_code = 35 if state == "New Mexico"
replace state_code = 36 if state == "New York"
replace state_code = 37 if state == "North Carolina"
replace state_code = 38 if state == "North Dakota"
replace state_code = 39 if state == "Ohio"
replace state_code = 40 if state == "Oklahoma"
replace state_code = 41 if state == "Oregon"
replace state_code = 42 if state == "Pennsylvania"
replace state_code = 44 if state == "Rhode Island"
replace state_code = 45 if state == "South Carolina"
replace state_code = 46 if state == "South Dakota"
replace state_code = 47 if state == "Tennessee"
replace state_code = 48 if state == "Texas"
replace state_code = 49 if state == "Utah"
replace state_code = 50 if state == "Vermont"
replace state_code = 51 if state == "Virginia"
replace state_code = 53 if state == "Washington"
replace state_code = 54 if state == "West Virginia"
replace state_code = 55 if state == "Wisconsin"
replace state_code = 56 if state == "Wyoming"

gen evolution_score=.
replace evolution_score=9 if state_code==1 & year<2005
replace evolution_score=21 if state_code==1 & year>=2005
replace evolution_score=48 if state_code==2 & year<2006
replace evolution_score=59 if state_code==2 & year>=2006
replace evolution_score=82 if state_code==4 & year<2005
replace evolution_score=82 if state_code==4 & year>=2005
replace evolution_score=55 if state_code==5 & year<2005
replace evolution_score=66 if state_code==5 & year>=2005
replace evolution_score=100 if state_code==6
replace evolution_score=86 if state_code==8 & year<2009
replace evolution_score=82 if state_code==8 & year>=2009
replace evolution_score=100 if state_code==9 & year<2004
replace evolution_score=59 if state_code==9 & year>=2004
replace evolution_score=91 if state_code==10 & year<2006
replace evolution_score=80 if state_code==10 & year>=2006
replace evolution_score=80 if state_code==11 & year<2006
replace evolution_score=96 if state_code==11 & year>=2006
replace evolution_score=16 if state_code==12 & year<2008
replace evolution_score=91 if state_code==12 & year>=2008
replace evolution_score=7 if state_code==13 & year<2004
replace evolution_score=66 if state_code==13 & year>=2004
replace evolution_score=91 if state_code==15 & year<2005
replace evolution_score=75 if state_code==15 & year>=2005
replace evolution_score=82 if state_code==16 & year<2007
replace evolution_score=82 if state_code==16 & year>=2007
replace evolution_score=45 if state_code==17 & year<2004
replace evolution_score=82 if state_code==17 & year>=2004
replace evolution_score=100 if state_code==18 & year<2006
replace evolution_score=96 if state_code==18 & year>=2006
replace evolution_score=77 if state_code==19 & year>=2007
replace evolution_score=0 if state_code==20 & year<2007
replace evolution_score=96 if state_code==20 & year>=2007
replace evolution_score=55 if state_code==21 & year<2006
replace evolution_score=55 if state_code==21 & year>=2006
replace evolution_score=64 if state_code==22 & year<2005
replace evolution_score=27 if state_code==22 & year>=2005
replace evolution_score=30 if state_code==23 & year<2007
replace evolution_score=68 if state_code==23 & year>=2007
replace evolution_score=77 if state_code==24 & year<2002
replace evolution_score=73 if state_code==24 & year>=2002
replace evolution_score=82 if state_code==25 & year<2006
replace evolution_score=84 if state_code==25 & year>=2006
replace evolution_score=84 if state_code==26 & year<2000
replace evolution_score=80 if state_code==26 & year>=2000
replace evolution_score=86 if state_code==27 & year<2009
replace evolution_score=89 if state_code==27 & year>=2009
replace evolution_score=5 if state_code==28 & year<2008
replace evolution_score=87 if state_code==28 & year>=2008
replace evolution_score=82 if state_code==29 & year<2008
replace evolution_score=78 if state_code==29 & year>=2008
replace evolution_score=82 if state_code==30 & year<2006
replace evolution_score=75 if state_code==30 & year>=2006
replace evolution_score=66 if state_code==31 
replace evolution_score=70 if state_code==32 & year<2004
replace evolution_score=77 if state_code==32 & year>=2004
replace evolution_score=23 if state_code==33 & year<2006
replace evolution_score=91 if state_code==33 & year>=2006
replace evolution_score=100 if state_code==34 & year<2002
replace evolution_score=100 if state_code==34 & year>=2002
replace evolution_score=73 if state_code==35 & year<2003
replace evolution_score=91 if state_code==35 & year>=2003
replace evolution_score=68 if state_code==36
replace evolution_score=100 if state_code==37 & year<2004
replace evolution_score=82 if state_code==37 & year>=2004
replace evolution_score=9 if state_code==38 & year<2006
replace evolution_score=64 if state_code==38 & year>=2006
replace evolution_score=30 if state_code==39 & year<2006
replace evolution_score=86 if state_code==39 & year>=2006
replace evolution_score=25 if state_code==40 & year<2005
replace evolution_score=25 if state_code==40 & year>=2005
replace evolution_score=82 if state_code==41 & year<2009
replace evolution_score=82 if state_code==41 & year>=2009
replace evolution_score=91 if state_code==42 & year<2002
replace evolution_score=96 if state_code==42 & year>=2002
replace evolution_score=100 if state_code==44 & year<2006
replace evolution_score=82 if state_code==44 & year>=2006
replace evolution_score=95 if state_code==45 & year<2005
replace evolution_score=91 if state_code==45 & year>=2005
replace evolution_score=82 if state_code==46 & year<2005
replace evolution_score=77 if state_code==46 & year>=2005
replace evolution_score=2 if state_code==47 & year<2007
replace evolution_score=55 if state_code==47 & year>=2007
replace evolution_score=64 if state_code==48 & year<2009
replace evolution_score=46 if state_code==48 & year>=2009
replace evolution_score=82 if state_code==49 & year<2003
replace evolution_score=82 if state_code==49 & year>=2003
replace evolution_score=86 if state_code==50 & year<2000
replace evolution_score=86 if state_code==50 & year>=2000
replace evolution_score=50 if state_code==51 & year<2003
replace evolution_score=68 if state_code==51 & year>=2003
replace evolution_score=86 if state_code==53 & year<2005
replace evolution_score=86 if state_code==53 & year>=2005
replace evolution_score=2 if state_code==54 & year<2008
replace evolution_score=46 if state_code==54 & year>=2008
replace evolution_score=55 if state_code==55
replace evolution_score=36 if state_code==56 & year<2003
replace evolution_score=61 if state_code==56 & year>=2003
gen evo_score = evolution_score/100
label variable evo_score "Evolution Score"

save "${path}\data\text\text_ready.dta", replace



